#pragma once

#include "Common.h"

class ThreadCache
{
public:
	//申请内存对象
	void *Allocate(size_t size);
	//释放内存对象
	void Deallocate(void *ptr, size_t size);
	//从CentralCache获取对象
	void *FetchFromCentralCache(size_t index, size_t size);
	//链表太长时将部分链表还给CentralCache
	void ListTooLong(FreeList &list, size_t size);

	//获取第i个_freeLists
	FreeList &GetFreeList(int i)
	{
		return _freeLists[i];
	}

private:
	FreeList _freeLists[NUM_FREE_LIST];
};
//使用TLS
//每个线程都有一个pTLSThreadCache变量，这样就能防止多线程之间冲突
static TLS ThreadCache *pTLSThreadCache = nullptr;